package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.QueryMemberByMobileBean;
import com.shop2cn.iapi.member.service.QueryMemberByMobileCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.TestDataManager;
/**
*根据手机号查询电铺会员
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_QueryMemberByMobile{
	private static QueryMemberByMobileBean querymemberbymobileBean;
	private static QueryMemberByMobileCall querymemberbymobileCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据手机号查询电铺会员");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		querymemberbymobileBean=new QueryMemberByMobileBean();
		querymemberbymobileCall=new QueryMemberByMobileCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(querymemberbymobileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberByMobile_001() {
		Logger.start(true,"根据手机号查询电铺会员成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			querymemberbymobileBean.setMobile(mobile);
			querymemberbymobileBean.setShopId(shopid);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("200", querymemberbymobileCall.getString("code"), "验证code");
			Logger.verifyEquals(memid, querymemberbymobileCall.getQueryMemberByMobileResp().getMemberId(),"验证memid");
			Logger.verifyEquals(userId, querymemberbymobileCall.getQueryMemberByMobileResp().getUserId(),"验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberByMobile_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			querymemberbymobileBean.setMobile("13712163581");
//			querymemberbymobileBean.setShopId(shopid);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("400", querymemberbymobileCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberByMobile_003() {
		Logger.start(true,"不输入mobile失败");
		try {
//			querymemberbymobileBean.setMobile("13712163581");
			querymemberbymobileBean.setShopId(shopid);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("400", querymemberbymobileCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_QueryMemberByMobile_004() {
		Logger.start(true,"输入shopid和mobile不匹配失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			String mobile=TestDataManager.getPhoneNum();
			GodMemberService.bindMobile(shopid, userId, mobile);
			querymemberbymobileBean.setMobile(mobile+1);
			querymemberbymobileBean.setShopId(shopid);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("200", querymemberbymobileCall.getString("code"), "验证code");
			//条件错误查询不到
			Logger.verifyEquals(null, querymemberbymobileCall.getQueryMemberByMobileResp().getMemberId(),"验证memid");
			Logger.verifyEquals(0, querymemberbymobileCall.getQueryMemberByMobileResp().getUserId(),"验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_QueryMemberByMobile_005() {
		Logger.start(true,"根据accessSource手机号查询电铺会员成功");
		try {
			String mobile=TestDataManager.getPhoneNum();
			//新建商家开启积分
			shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.mchSetOpenPoints(shopid, true);
			GodMemberService.MchSetOpenPointsRule(GodMemberService.initMchSetOpenPointsRuleBean(shopid));
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			GodMemberService.bindMobile(shopid, userId, mobile,null,1);
			
			
			UserCreateBean usercreateBean2 = DGUserCallService.initUsercreateBean();
			usercreateBean2.setAppSource(DGUserCallService.getAppSourceCode(4));
			int userId2 = DGUserCallService.UserCreateCall(usercreateBean2);
			CreateMemberBean createMem2 = GodMemberService.initCreateMemberBean(shopid,userId2,usercreateBean2.getOpenId());
			createMem2.setOpenId(usercreateBean2.getOpenId());
			createMem2.setAccessSource(4);
			String memid2 = GodMemberService.creatememberCall(createMem2);
			GodMemberService.bindMobile(shopid, userId2, mobile,null,4);
			
			UserCreateBean usercreateBean3 = DGUserCallService.initUsercreateBean();
			usercreateBean3.setAppSource(DGUserCallService.getAppSourceCode(6));
			int userId3= DGUserCallService.UserCreateCall(usercreateBean3);
			CreateMemberBean createMem3 = GodMemberService.initCreateMemberBean(shopid,userId3,usercreateBean3.getOpenId());
			createMem3.setOpenId(usercreateBean3.getOpenId());
			createMem3.setAccessSource(6);
			String memid3 = GodMemberService.creatememberCall(createMem3);
			GodMemberService.bindMobile(shopid, userId3, mobile,null,6);
			
			UserCreateBean usercreateBean4 = DGUserCallService.initUsercreateBean();
			usercreateBean4.setAppSource(DGUserCallService.getAppSourceCode(5));
			int userId4= DGUserCallService.UserCreateCall(usercreateBean4);
			CreateMemberBean createMem4 = GodMemberService.initCreateMemberBean(shopid,userId4,usercreateBean4.getOpenId());
			createMem4.setOpenId(usercreateBean4.getOpenId());
			createMem4.setAccessSource(5);
			String memid4 = GodMemberService.creatememberCall(createMem4);
			GodMemberService.bindMobile(shopid, userId4, mobile,null,5);
			
			querymemberbymobileBean.setAccessSource(1);
			querymemberbymobileBean.setMobile(mobile);
			querymemberbymobileBean.setShopId(shopid);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("200", querymemberbymobileCall.getString("code"), "验证code");
			Logger.verifyEquals(memid, querymemberbymobileCall.getQueryMemberByMobileResp().getMemberId(),"验证memid");
			Logger.verifyEquals(userId, querymemberbymobileCall.getQueryMemberByMobileResp().getUserId(),"验证userid");
			
			querymemberbymobileBean.setAccessSource(4);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("200", querymemberbymobileCall.getString("code"), "验证code");
			Logger.verifyEquals(memid2, querymemberbymobileCall.getQueryMemberByMobileResp().getMemberId(),"验证memid");
			Logger.verifyEquals(userId2, querymemberbymobileCall.getQueryMemberByMobileResp().getUserId(),"验证userid");
			
			querymemberbymobileBean.setAccessSource(6);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("200", querymemberbymobileCall.getString("code"), "验证code");
			Logger.verifyEquals(memid3, querymemberbymobileCall.getQueryMemberByMobileResp().getMemberId(),"验证memid");
			Logger.verifyEquals(userId3, querymemberbymobileCall.getQueryMemberByMobileResp().getUserId(),"验证userid");
			
			
			querymemberbymobileBean.setAccessSource(5);
			querymemberbymobileCall.setData(querymemberbymobileBean);
			querymemberbymobileCall.callService();			
			Logger.verifyEquals("200", querymemberbymobileCall.getString("code"), "验证code");
			Logger.verifyEquals(memid4, querymemberbymobileCall.getQueryMemberByMobileResp().getMemberId(),"验证memid");
			Logger.verifyEquals(userId4, querymemberbymobileCall.getQueryMemberByMobileResp().getUserId(),"验证userid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}